"""
 使用 while 和 for…in 两个循环分别输出四种九九乘法表效果（共计 8 个）。
"""
# while循环输出九九乘法表

# 第一种九九乘法表
print('*' * 30, 'while循环输出九九乘法表', '*' * 30)
# 定义行row，初始值为1
row = 1
while row < 10:
    # 定义列col，初始值为1
    col = 1
    # 循环输出col值，范围为【1，row】
    while col <= row:
        print('{}*{}={:<2}'.format(col, row, col * row), end=' ')
        col = col + 1
    # 换行
    print('')
    # row自增
    row = row + 1
print('=' * 60)

# 第二种九九乘法表
# 定义行值
row = 9
while row > 0:
    # 定义列值
    col = 1
    while col <= row:
        print('{}*{}={:<2}'.format(col, row, col * row), end=' ')
        col = col + 1
    # 换行，输出下一行
    print('')
    # 行值自减
    row = row - 1
print('=' * 60)

# 第三种九九乘法表
# 定义行值
row = 1
while row < 10:
    # 设置循环，输出前方空白区域
    flag = 9
    while flag > row:
        print(' ' * 6, end=' ')
        flag = flag - 1
    # 输出九九乘法表
    col = row
    while col >= 1:
        print('{}*{}={:<2}'.format(col, row, row * col), end=' ')
        col = col - 1
    print('')
    row = row + 1
print('=' * 60)

# 第四种九九乘法表
# 定义行值
row = 9
while row > 0:
    # 循环输出空白区域
    flag = 9
    while flag > row:
        print(' ' * 6, end=' ')
        flag = flag - 1
    # 输出九九乘法表
    col = row
    while col > 0:
        print('{}*{}={:<2}'.format(col, row, col * row), end=' ')
        col = col - 1
    print('')
    row = row - 1
print('=' * 60)

# for ...in...输出四个九九乘法表
print('*' * 30, 'for ...in...输出九九乘法表', '*' * 30)

for row in range(1, 10):
    for col in range(1, row + 1):
        print('{}*{}={:<2}'.format(col, row, col * row), end=' ')
    print('')
print('=' * 60)

for row in range(9, 0, -1):
    for col in range(1, row + 1):
        print('{}*{}={:<2}'.format(col, row, col * row), end=' ')
    print('')
print('=' * 60)

for row in range(1, 10):
    for flag in range(1, 10 - row):
        print(' ' * 6, end=' ')
    for col in range(row, 0, -1):
        print('{}*{}={:<2}'.format(col, row, col * row), end=' ')
    print('')
print('=' * 60)

for row in range(9, 0, -1):
    for flag in range(0, 9 - row):
        print(' ' * 6, end=' ')
    for col in range(row, 0, -1):
        print('{}*{}={:<2}'.format(col, row, col * row), end=' ')
    print(' ')
print('=' * 60)
